home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / DEL0_110.ZIP / DEL0.PAS < prev    next >
Pascal/Delphi Source File  |  1995-09-29  |  2KB  |  83 lines

  1. PROGRAM Delete0ByteFiles;
  2. {$M 1536,0,0}  { 1.5k reserved for data }
  3. {$N-,E- no math support needed}
  4. {$X- function calls may not be discarded}
  5. {$I- disable I/O checking (trap errors by checking IOResult)}
  6. {$S- no stack checking needed here}
  7.  
  8. USES DOS;
  9.  
  10. FUNCTION IsDir (CONST FileName: PATHSTR): BOOLEAN;
  11. VAR
  12.   Attr  : WORD;
  13.   cFile : FILE;
  14. BEGIN
  15.   Assign (cFile, FileName);
  16.   GetFAttr (cFile, Attr);
  17.   IF (DosError = 0) AND ((Attr AND Directory) = Directory)
  18.     THEN IsDir := TRUE
  19.     ELSE IsDir := FALSE;
  20. END;
  21.  
  22. FUNCTION GetFilePath (CONST PSTR: STRING; VAR sDir: DIRSTR): PATHSTR;
  23. VAR
  24.   jPath     : PATHSTR;  { file path,       }
  25.   jDir      : DIRSTR;   {      directory,  }
  26.   jName     : NAMESTR;  {      name,       }
  27.   jExt      : EXTSTR;   {      extension.  }
  28. BEGIN
  29.   jPath := PSTR;
  30.   IF jPath = '' THEN jPath := '*.*';
  31.   IF (NOT (jPath [Length (jPath)] IN [':', '\'])) AND IsDir (jPath) THEN
  32.     jPath := jPath + '\';
  33.   IF (jPath [Length (jPath)] IN [':', '\']) THEN
  34.     jPath := jPath + '*.*';
  35.  
  36.   FSplit (FExpand (jPath), jDir, jName, jExt);
  37.   jPath := jDir + jName+ jExt;
  38.  
  39.   sDir := jDir;
  40.   GetFilePath := jPath;
  41. END;
  42.  
  43. CONST
  44.   NL = #13#10;
  45. VAR
  46.   fPath     : PATHSTR;
  47.   fDir      : DIRSTR;
  48.   DirInfo   : SEARCHREC;
  49.   fFile     : FILE;
  50.   Deleted   : WORD;
  51.  
  52. BEGIN
  53.   WriteLn ('DEL0 v1.10 - Free DOS utility: Zero byte file deleter.');
  54.   WriteLn ('September 29, 1995. Copyright (c) 1995 by David Daniel Anderson - Reign Ware.' + NL);
  55.  
  56.   Deleted := 0;
  57.   IF ParamCount <> 1 THEN
  58.   BEGIN
  59.     WriteLn ('Usage: DEL0 FileMask');
  60.     Halt (1);
  61.   END;
  62.   fPath := GetFilePath (ParamStr (1), fDir);
  63.  
  64.   FindFirst (fPath, Archive, DirInfo);
  65.   WHILE DosError = 0 DO
  66.   BEGIN
  67.     fPath := fDir + DirInfo. Name;
  68.     Assign (fFile, fPath);
  69.     IF (DirInfo. Size = 0) THEN BEGIN
  70.       Write ('Deleting ', fPath);
  71.       Erase (fFile);
  72.       IF IOResult = 0
  73.         THEN WriteLn (', done!')
  74.         ELSE WriteLn (' - unable to delete.');
  75.       Inc (Deleted)
  76.     END;
  77.  
  78.     FindNext (DirInfo);
  79.   END;
  80.   IF Deleted > 0 THEN WriteLn;
  81.   WriteLn ('Files deleted: ', Deleted);
  82. END.
  83.